package com.lsk.admin.shop;

import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.aop.Duang;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.upload.UploadFile;
import com.lsk.admin.interceptor.SessionInterceptor;
import com.lsk.util.*;
import org.apache.commons.lang.StringUtils;

import java.util.*;

/**
 * Created by Administrator on 2018/7/16 0016.
 */
public class ShopController extends Controller {
    ShopServices txShopServices = Duang.duang(new ShopServices());
    ShopServices shopServices = new ShopServices();
    CardService cardService = new CardService();

    /**
     * 商品列表
     */
    public void commodityList() {

        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        String type = getPara("type");
        String classId=getPara("classId");
        PageUtil pageUtil = shopServices.commodityListService(page, limit, type,classId);
        setAttr("pageUtil", pageUtil);
        setAttr("type", type);
        setAttr("classId",classId);
        renderJsp("commodityList.jsp");
    }

    /**
     * 商品类型列表
     */
    public void classTypeList() {
        String cType= StringUtils.isNotBlank(getPara("cType"))?getPara("cType"):"0";
        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "4" : limit;
        PageUtil pageUtil = shopServices.getCommodityClassList(page, limit,cType);
        setAttr("pageUtil", pageUtil);
        setAttr("cType",cType);
        renderJsp("classTypeList.jsp");
    }


    /**
     * 去编辑商品页面
     */
    public void editCommodity() {
        String id = getPara("id");
        String type = getPara("type");
        String classId=getPara("classId");
        Record record = new Record();
        if (id != null && !"".equals(id)) {
            record = shopServices.editCommodityService(id);
        }
        /*商品分类列表*/
        List<Record> classList = shopServices.getAllCommodityClassService("0", "999",type);
        setAttr("classList", classList);
        setAttr("record", record);
        setAttr("type", type);
        setAttr("classId",classId);
        renderJsp("editCommodity.jsp");
    }

    /**
     * 去编辑热门商品页面
     */
    public void editHotCommodity() {
        String id = getPara("id");
        Record record = shopServices.editCommodityService(id);
        /*商品分类列表*/
        //type=null表示查找所有的商品
        List<Record> commodityList = shopServices.commodityListService("1", "999", null,null).getList();
        setAttr("commodityList", commodityList);
        setAttr("record", record);
        renderJsp("editHotCommodity.jsp");
    }

    /**
     * 删除商品
     */
    public void delCommodity() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.delCommodityService(map);
        renderJson(returnData);
    }

    public void delClassType() {
        String id = getPara("id");
        ReturnData rd = shopServices.delClassType(id);
        renderJson(rd);
    }


    /**
     * 删除热门商品
     */
    public void delHotCommodity() {

        String id = getPara("id");

        Record record = new Record().set("id", id).set("hotNumber", null);

        boolean up = Db.update("commodity", "id", record);

        renderJson(new ReturnData(up));
    }

    /**
     * 去编辑类型页面
     */
    public void editClassType() {
        String id = getPara("id");
        String cType=getPara("cType");
        Record record = shopServices.classTypeByIdService(id,cType);
        setAttr("record", record);
        setAttr("id",id);
        renderJsp("editClassType.jsp");
    }

    /**
     * 编辑显示
     */
    public void kaPingtai() {
        String id = getPara("id");
        Record record = shopServices.kaPingtai(id);
        setAttr("record", record);
        renderJsp("xiugaiPingtai.jsp");
    }

    /**
     * 单个图片上传
     */

    public void imgUpload() {



        UploadFile file = getFile();

//        type = file.getContentType().equals(type) == false ? "jpg" : type;
//
//        String path = PropKit.get("rootPath") + "/upload/" + UtilUUID.getUUID() + "." + type;
//
//        file.getFile().renameTo(new File(path));

        String imgUrl = QiNiuUploadUtil.localFileUpload( file.getUploadPath()+"/"+ file.getOriginalFileName());

        Map map = new HashMap();

        map.put("code", "0");
        map.put("msg", "上传成功");
        Map data = new HashMap();
        data.put("src", imgUrl);
        data.put("title", "");
        map.put("data", data);
        renderJson(map);
    }


    /**
     * 其中商品Id从commodityList传入facevaluelist中的一个隐藏域中
     * 面值列表
     *
     * @param
     */

    public void faceValueList() {
        //其中商品Id从commodityList传入facevaluelist中的一个隐藏域中
        String commodityId = getPara("commodityId");
        double discount = shopServices.editCommodityService(commodityId).get("discount");
        setAttr("commodityDiscount", discount);
        setAttr("commodityId", commodityId);
        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        PageUtil pageUtil = shopServices.commodityFaceValueListService(page, limit, commodityId);

        setAttr("commodityId", commodityId);

        setAttr("pageUtil", pageUtil);

        renderJsp("faceValueList.jsp");

    }

    /**
     * 增加和更新face value.通过id值是否存在判断是更新或修改
     */
    public void toEditFaceValue() {
        String id = getPara("id");
        String commodityId = getPara("commodityId");
        String commodityDiscount = getPara("commodityDiscount");
        if (id != null && !id.isEmpty()) {
            //更新
            Record record = shopServices.getFaceValueById(id);
            setAttr("record", record);
        }
        //将商品ID传给页面
        setAttr("commotidyId", commodityId);
        setAttr("commodityDiscount", commodityDiscount);

        renderJsp("editFaceValue.jsp");
    }

    public void pingtaiUpsa() {
        String id = getPara("id");
        String productId = getPara("productId");
        String prodictName = getPara("productName");
        if (id != null && id.isEmpty()) {
            Record record = shopServices.pingtaiId(id);
            setAttr("record", record);
        }
        setAttr("productId", productId);
        setAttr("productName", productId);
        renderJsp("xiugaiPingtai.jsp");
    }

    /**
     * 保存faceValue数据
     */
    public void saveFaceValue() {
        Map<String, String[]> map = getParaMap();
        ReturnData rd = shopServices.saveFaceValue(map);
        renderJson(rd);
    }

    /**
     * 保存平台
     */
    public void savePingtai() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.updaSave(map);
        renderJson(returnData);
    }

    /**
     * 根据Id删除facevalue
     */
    public void delFaceValue() {
        ReturnData rd = new ReturnData();
        String id = getPara("id");
        String delSql = "delete from commodity_facevalue where id = '" + id + "'";
        int result = Db.delete(delSql);
        //设置返回结果
        rd.setResult(result >= 0 ? true : false);

        if (result >= 0) {
            rd.setMsg("保存成功");
            rd.setCode("000000");
        } else {
            rd.setMsg("保存失败");
            rd.setCode("111111");
        }
        renderJson(rd);
    }

    /**
     * 保存商品
     */
    public void saveCommodity() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.saveCommodityService(map);
        renderJson(returnData);
    }

    /**
     * 保存热门商品序号
     */
    public void saveHotCommodity() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.saveHotCommodityService(map);
        renderJson(returnData);

    }

    /**
     * 保存商品类型
     */
    public void saveClassType() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.saveClassTypeService(map);
        renderJson(returnData);

    }

    /**
     * 保存
     */
    public void sevaPingtai() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.savePingtai(map);
        renderJson(returnData);
    }


    /**
     * 注册商户
     */
    @Clear(SessionInterceptor.class)
    @Before(Tx.class)
    public void registerMerchant() throws Exception {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = txShopServices.registerMerchantService(map);
        renderJson(returnData);
    }

    /**
     * 保存商户
     */
    public void saveShopInfo() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = txShopServices.saveShopInfoServie(map);
        renderJson(returnData);
    }

    /**
     * 店铺-商品配置
     */
    public void shopProductList() {
        String id = getPara("id");
        setAttr("id", id);
        renderJsp("shopProduct.jsp");
    }

    public void shopProductListData() {
        String id = getPara("id");
        int page = getParaToInt("page");
        int limit = getParaToInt("limit");
        Map map = txShopServices.shopProductListData(id, page, limit);
        renderJson(map);
    }

    /**
     * 店家-商品价格设定信息
     */
    public void shopProductSetting() {
        String id = getPara("id");
        String money = getPara("money");
        String state = getPara("state");
        String name = getPara("name");
        String prouctId = getPara("prouctId");
        String shopId = getPara("shopId");
        setAttr("id", id);
        setAttr("money", money);
        setAttr("state", state);
        setAttr("name", name);
        setAttr("prouctId", prouctId);
        setAttr("shopId", shopId);
        renderJsp("shopProductSetting.jsp");
    }

    /**
     * 保存设定信息
     */
    public void saveShopProductSetting() {
        String id = getPara("id");
        String money = getPara("money").trim();
        String state = getPara("state");
        String shopId = getPara("shopId").trim();
        String prouctId = getPara("prouctId");
        ReturnData returnData = shopServices.saveShopProductSettingService(id, money, state, prouctId, shopId);
        renderJson(returnData);
    }


    /**
     * 去商铺详情页面
     */
    public void goShopInfo() {
        String id = getPara("id");
        Record record = shopServices.getShopInfoService(id);
        setAttr("shop", record);
        renderJsp("shopInfo.jsp");
    }

    /**
     * 商铺列表
     */
    public void shopList() {
        renderJsp("shopList.jsp");
    }

    /**
     * 商铺列表
     */
    public void shopListData() {
        int page = getParaToInt("page");
        int limit = getParaToInt("limit");
        Map map = shopServices.shopListDataService(page, limit);
        renderJson(map);
    }

    /**
     * 首页轮播图
     */
    public void slideshowList() {

        String ctype=getPara("type");

        List<Record> list = shopServices.getSlideshowListService(ctype);

        setAttr("cType",ctype);


        setAttr("recordList", list);

        renderJsp("slideshowList.jsp");
    }

    /**
     * 去编辑轮播图
     */
    public void editSlideshow() {
        String id = getPara("id");
        Record record = shopServices.getSlideshowInfo(id);
        setAttr("record", record);
        renderJsp("editSlideshow.jsp");

    }

    /**
     * 保存轮播图
     */
    public void saveSlideshow() {

        Map<String, String[]> map = getParaMap();

        ReturnData returnData = shopServices.saveSlideshowService(map);

        renderJson(returnData);

    }

    /**
     * 热门回收
     */
    public void hot() {

        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        PageUtil pageUtil = shopServices.hotService(page, limit);
        setAttr("pageUtil", pageUtil);
        renderJsp("hotList.jsp");

    }

    /**
     * 公告列表
     */
    public void noticeList() {

        String page = getPara("page");

        page = page == null || "".equals(page) ? "1" : page;

        String limit = getPara("limit");

        limit = limit == null || "".equals(limit) ? "10" : limit;

        String type = StringUtils.isNotBlank(getPara("type"))?getPara("type"):"0";;

        PageUtil pageUtil = shopServices.noticeListService(page, limit ,type);

        setAttr("pageUtil", pageUtil);
        setAttr("type",type);

        renderJsp("noticeList.jsp");

    }

    /**
     * 编辑公告
     */
    public void editNotice() {

        String id = getPara("id");

        String type=getPara("type");

        Record record = shopServices.getNoticeInfo(id,type);

        setAttr("notice", record);

        renderJsp("editNotice.jsp");

    }

    /**
     * 保存公告
     */
    public void saveNotice() {

        Map<String, String[]> map = getParaMap();

        ReturnData returnData = shopServices.saveNoticeService(map);

        renderJson(returnData);
    }

    /**
     * 删除公告
     */
    public void removedAdvice() {
        String id = getPara("id");
        boolean flag = Db.deleteById("notice", id);
        ReturnData rd = new ReturnData(flag);
        renderJson(rd);
    }

    /**
     * 显示id
     */
    public void Show() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        PageUtil pageUtil = shopServices.ShowService(page, limit);
        setAttr("pageUtil", pageUtil);
        renderJsp("Show.jsp");
    }

    /**
     * 删除轮播
     */
    public void delSlideshow() {
        String id = getPara("id");
        int row = Db.delete("delete from slideshowimg where id=?", id);
        ReturnData rd = new ReturnData();
        if (row >= 1) {
            rd.setResult(true);
        } else {
            rd.setResult(false);
        }
        renderJson(rd);
    }

    /**
     * 查询dataStatistics(分页和搜索)
     */
    public void dataStatistics() {
        Map paraMap = getParaMap();
        PageUtil pageUtil = shopServices.getStatisticsList(paraMap);
        List<Record> list = pageUtil.getList();
        int count = pageUtil.getTotalRows();
        Map<String, Object> map = new HashMap();
        map.put("code", 0);
        if (count > 0) {
            map.put("count", count);
            map.put("data", list);
        } else {
            map.put("count", 0);
            map.put("msg", "暂无数据");
        }
        renderJson(map);
    }

    /**
     * 今天订单以及总订单
     */
    public void statisticsDataSum() {

        String date=DateUtil.getDay();
        ReturnData data = shopServices.getSum(date);
        renderJson(data);
    }

    /**
     * 跳转到数据统计页面
     */
    public void toDataStatistics() {

        String startDate=getPara("startDate");


        String endDate=getPara("endDate");


        String cardName=getPara("cardName");

        String payState=getPara("payState");

        String feedbackValue=getPara("feedbackValue");

        startDate=startDate==null?DateUtil.getAfterDayDate("-3").substring(0,10):startDate;

        endDate=endDate==null?DateUtil.getDay():endDate;

        List<String> classNames = Db.query("select name from commodity_class group by name");
        setAttr("classNames",classNames);

        setAttr("cardName",cardName);

        setAttr("startDate",startDate);

        setAttr("endDate",endDate);

        setAttr("feedbackValue",feedbackValue);

        setAttr("payState",payState);

        renderJsp("dataStatistics.jsp");

    }

    /**
     * 订单详情页
     */
    public void orderDetails(){
        String cardId = getPara("cardId");
        String sql="select * from card_send_logs where cardId='" + cardId + "'";
        Record first = Db.findFirst(sql);
        //查出出付款详情

        String payLogSql="SELECT *from apply_logs WHERE cardId='"+cardId+"'";

        Record payLog=Db.findFirst(payLogSql);

        setAttr("payLog",payLog);

        setAttr("data",first);
        setAttr("cardId",cardId);
        renderJsp("orderDetails.jsp");
    }

    public void orderDetailsInfo(){
        String page=getPara("page");
        page=StringUtils.isBlank(page)?"1":page;
        String limit=getPara("limit");
        limit=StringUtils.isBlank(limit)?"5":limit;
        String cardId = getPara("cardId");
        String sql="select * from card_send_logs where cardId='" + cardId + "'";
        PageUtil pageUtil=new PageUtil(Integer.parseInt(page),Integer.parseInt(limit),sql);
        ReturnData returnData=new ReturnData(true);
        returnData.setData(pageUtil.getList());
        renderJson(returnData);
    }

    /**
     * 统计明细
     */
    public void statisticsInfo(){

       String type=getPara("type");

        String date=getPara("date");

        date=date==null?DateUtil.getDay():date;

        setAttr("date",date);

        setAttr("type",type);

        renderJsp("dataStatisticsInfo.jsp");

    }
    /**
     * 统计明细
     */
    public void statisticsInfoData(){

        String type=getPara("type");

        String date=getPara("date");

        date=date==null?DateUtil.getDay():date;

        Map map=shopServices.statisticsDataInfoDataService(type,date);

        renderJson(map);

    }


    /**
     * 接口开关
     */
    public void interfaceSwitch() {
        boolean amend = GlobalParameter.yjfstate;
        boolean alter = GlobalParameter.xkstate;
        Map<String, Boolean> map = new HashMap<>();
        map.put("yjf", amend);
        map.put("xk", alter);
        ReturnData rd = new ReturnData(true);
        rd.setData(map);
        rd.setCode("111111");
        renderJson(rd);

    }

    /**
     * 去接口开关页面
     */
    public void modifiCation() {
        ReturnData rd = shopServices.NetList();
        setAttr("data", rd);
        renderJsp("modifiCation.jsp");
    }

    /**
     * 修改接口开关状态
     */
    public void setWebOn() {
        String element = getPara("element");
        String value = getPara("value");
        ReturnData rd = shopServices.setInterfaceState(element, value);
        renderJson(rd);
    }

    /**
     * 展示关联页面
     */
    public void showXK() {
        String id = getPara("id");
        String xkId = getPara("xkId");
        String page = getPara("page");
        String limit = getPara("limit");
        String key=getPara("key");
        page = (page == null || "".equals(page) ? "1" : page);
        limit = (limit == null || "".equals(limit) ? "6" : limit);
        PageUtil pageUtil = shopServices.showXKList(limit, page, key);
        setAttr("id", id);
        setAttr("xkId", xkId);
        setAttr("key",key);
        setAttr("pageUtil", pageUtil);
        renderJsp("xkList.jsp");
    }

    /**
     * 取消或设定闲卡关联
     */
    public void cancelConn() {
        String feedbackId = getPara("feedbackId");
        String xkId = getPara("xkId");
        boolean isConn = getParaToBoolean("isConn");
        ReturnData rd = shopServices.cancelConn(xkId, isConn, feedbackId);
        renderJson(rd);
    }

    /**
     * 展示收卡啦列表
     */
    public void showSK() {
        String id = getPara("id");
        String page = getPara("page");
        String limit = getPara("limit");
        String skId = getPara("skId");
        String key=getPara("key");
        page = (page == null || "".equals(page) ? "1" : page);
        limit = (limit == null || "".equals(limit) ? "5" : limit);
        PageUtil pageUtil = shopServices.showSKList(limit, page,key);
        setAttr("skId", skId);
        setAttr("key",key);
        setAttr("id", id);
        setAttr("pageUtil", pageUtil);
        renderJsp("skList.jsp");
    }

    /**
     * 取消或设定收卡关联
     */
    public void cancelSKConn() {
        String id = getPara("id");        //commodityId
        boolean isConn = getParaToBoolean("isConn");
        String skId = getPara("skId");
        ReturnData rd = shopServices.cancelSKConn(skId, isConn, id);
        renderJson(rd);
    }

    /**
     * 显示闲卡
     */
    public void showXianka() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        String commodityTypeId = getPara("type");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        Map<String, String[]> map = getParaMap();
        PageUtil pageUtil = shopServices.showKa(page, limit, commodityTypeId);
        ReturnData topReturnData = shopServices.caidan();
        List<Record> topMenu = (List<Record>) topReturnData.getData();
        setAttr("topMenu", topMenu);
        setAttr("pageUtil", pageUtil);
        setAttr("commodityTypeId", commodityTypeId);
        renderJsp("showKa.jsp");
    }
    /**
     * 速效卡--配置
     */
    public void showSuXiaoKa() {
        String faceValueId=getPara("faceValueId");
        if (StringUtils.isNotBlank(faceValueId)) {
            //速销卡只能关联到商品，此处将面值替换成商品ID
            String sql="SELECT *from commodity_facevalue where id='"+faceValueId+"'";
            Record commo=Db.findFirst(sql);
            String  sxkCommodityId=commo.getStr("sxkCommodityId");
            setAttr("facevalueId",faceValueId);
            setAttr("sxkCommodityId",sxkCommodityId);
        }

        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;

        PageUtil pageUtil = shopServices.showSuXiaoKa(page, limit,faceValueId);
        setAttr("pageUtil", pageUtil);
        renderJsp("showSXK.jsp");
    }

    /**
     * 设定面值与速效卡的关联
     */
     public void saveSXKFaceValueId(){
         String facevalueId=getPara("facevalueId");
         String id=getPara("id");
         boolean isConn = getParaToBoolean("hasNumber");
         String upSql="";

         if (isConn){
             // 关联
             String faceSql="SELECT *from commodity_facevalue where id='"+facevalueId+"'";
             Record record=Db.findFirst(faceSql);
              //upSql="UPDATE commodity_sxk SET facevalueId='"+facevalueId+"' WHERE id='"+id+"'";
             String commodityId=record.getStr("commodityId");
             upSql="UPDATE commodity_facevalue SET sxkCommodityId = '"+id+"' where commodityId='"+commodityId+"'";
         } else {
             upSql="UPDATE  commodity_facevalue SET sxkCommodityId='' where id='"+facevalueId+"'";
         }
         Db.update(upSql);
         renderJson(new ReturnData(true));
     }






    /**
     * 设定序号number
     */
    public void apiNumber() {

        String id = getPara("id");

        setAttr("id", id);

        List<Record> list = shopServices.apiNumberService(id);

        setAttr("list", list);

        renderJsp("apiNumber.jsp");

    }

    /**
     * 保存接口序号
     */
    public void saveApiNumber() {

        Map map = getParaMap();

        ReturnData returnData = shopServices.saveApiNumberService(map);

        renderJson(returnData);
    }

    /**
     * 去配置支付信息页面
     */
    public void toPayInfo() {
        ReturnData rd = shopServices.getElementsList();
        setAttr("list", rd);
        renderJsp("payInfo.jsp");
    }

    /**
     * 修改支付信息
     */
    public void updatePayInfo() {
        String element = getPara("element");
        String value = getPara("value");
        ReturnData rd = shopServices.updatePayInfo(element, value);
        renderJson(rd);
    }

    /**
     * 因value过长,所以重新查询
     */
    public void getValueByElement() {
        String element = getPara("element");
        ReturnData rd = shopServices.getValueByElement(element);
        renderJson(rd);
    }

    /**
     * 显示其他平台商品
     */
    public void showPingtai() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        PageUtil pageUtil = shopServices.showPingtai(page, limit);
        setAttr("pageUtil", pageUtil);
        renderJsp("showPingtai.jsp");
    }

    /**
     * 删除平台商品
     */
    public void delePingtai() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.delePingtai(map);
        renderJson(returnData);
    }

    /**
     * 修改
     */
    public void updaPing() {
        Map<String, String[]> map = getParaMap();
        ReturnData rd = shopServices.updasave(map);
        renderJson(rd);
    }


    /**
     * 修改
     */
    public void xiugai() {
        renderJsp("xiugaiPingtai.jsp");
    }

    /**
     * 会员查询
     */

    public void memberManagement() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "0" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        String type = getPara("type");
        String name = getPara("name");
        PageUtil pageUtil = shopServices.memberMan(page, limit, type, name);
        setAttr("pageUtil", pageUtil);
        setAttr("type", type);
        setAttr("name", name);
        renderJsp("memberManagement.jsp");
    }

    /**
     * 根据订单id获取付款详情页
     */
    public void payInfoList() {
        String id = getPara("id");
        Record record = shopServices.getAllPayInfo(id);
        setAttr("record", record);
        renderJsp("payInfoList.jsp");
    }

    @Before(Tx.class)
    public void toPayForMember() {
        ReturnData rd = new ReturnData();
        String cardId = getPara("cardId");
        String realName = getPara("realName");
        String money = getPara("money");
        String alipayAccount = getPara("alipayAccount");
        String alipayId = getPara("alipayId");
        Record record = shopServices.getOrderCardMemberByCardId(cardId);
        String orderId = record.get("orderId");
        String memberId = record.get("memberId");
        String cardNumber = record.get("cardNumber");
        Record param = new Record().set("cardId", cardId).set("realName", realName).set("money", money).set("cardNumber", cardNumber)
                .set("alipayAccount", alipayAccount).set("orderId", orderId).set("memberId", memberId).set("alipayId", alipayId);

        /**根据cardId向个人支付*/
        rd = shopServices.toPaybyCardId(cardId, money, realName, alipayAccount);

        renderJson(rd);
    }

    /**
     * 售卡记录
     */
    public void sellCardrecords() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        String id = getPara("id");
        PageUtil PageUtil = shopServices.cardRecords(id, page, limit);
        setAttr("id", id);
        setAttr("pageUtil", PageUtil);
        renderJsp("sellCard.jsp");
    }


    /**
     * 资金记录
     */
    public void moneyRecord() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "0" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        String id = getPara("id");
        PageUtil pageUtil = shopServices.moNey(id, page, limit);
        setAttr("id", id);
        setAttr("pageUtil", pageUtil);
        renderJsp("moneyRecord.jsp");
    }

    /**
     * 修改返利配置
     */
    public void editAgent(){
        String id=getPara("id");

        String memberId=getPara("memberId");

        String faceValueId=getPara("faceValueId");

        String faceSql="SELECT *from commodity_facevalue where id='"+faceValueId+"'";

        Record faceValue=Db.findFirst(faceSql);

        //查出来商品
        String commoditSql="SELECT *from commodity where id='"+faceValue.getStr("commodityId")+"'";

        Record commodit=Db.findFirst(commoditSql);

        Record record=shopServices.editAgent(id);
        setAttr("record",record);


        setAttr("id",id);
        setAttr("memberId",memberId);
        setAttr("faceValueId",faceValueId);

        setAttr("faceValue",faceValue);

        setAttr("commodit",commodit);

        renderJsp("editAgent.jsp");
    }

    /**
     * 保存返利配置
     */
    public void saveAgent(){
        Map<String, String[]> paraMap = getParaMap();
        ReturnData returnData=shopServices.saveAgent(paraMap);
        renderJson(returnData);
    }

    /**
     * 配置返利
     */
    public void agent() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "0" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "8" : limit;
        String id = getPara("id");
        String commodityName=getPara("commodityName");
        String faceValue=getPara("faceValue");
        PageUtil pageUtil = shopServices.agent(id, page, limit,commodityName,faceValue);
        setAttr("id", id);//会员id
        setAttr("commodityName",commodityName);
        setAttr("faceValue",faceValue);
        setAttr("pageUtil", pageUtil);
        renderJsp("agent.jsp");
    }

    /**
     * 代理商下级人员
     */
    public void subordinate(){
        String page = getPara("page");
        page = page == null || "".equals(page) ? "0" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "8" : limit;
        String id = getPara("id");
        String name=getPara("name");
        PageUtil pageUtil = shopServices.subordinate(id, page, limit,name);
        setAttr("id", id);
        setAttr("name",name);
        setAttr("pageUtil", pageUtil);
        renderJsp("subordinate.jsp");
    }

    /**
     * 添加下级
     */
    public void addSubordinate(){
        String id = getPara("id");
        String userId = getPara("userId");
        ReturnData returnData=shopServices.addSubordinate(id,userId);
        renderJson(returnData);
    }

    /**
     * 解除下级
     */
    public void delSubordinate(){
        String id = getPara("id");
        String userId = getPara("userId");
        ReturnData returnData=shopServices.delSubordinate(id,userId);
        renderJson(returnData);
    }

    public void accountRecord() {
        String page = getPara("page");
        page = page == null || "".equals(page) ? "0" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        String id = getPara("id");
        PageUtil PageUtil = shopServices.acoUnt(id, page, limit);
        setAttr("id", id);
        setAttr("PageUtil", PageUtil);
        renderJsp("accountRecord.jsp");
    }

    public void toBatchUpdateCardStatus() {
        String cardIds = getPara("cardIds");
        setAttr("cardIds", cardIds);
        renderJsp("batchUpdateCardStatus.jsp");
    }

    public void batchUpdateCardStatus() {
        String cardIds = getPara("cardIds");
        if (StringUtils.isNotBlank(cardIds)) {
            String state = getPara("state");
            List<String> cardIdList = Arrays.asList(cardIds.split(","));
            cardService.batchUpdateCardStatus(cardIdList, Integer.parseInt(state));
        }
        renderJson(ReturnData.success());
    }

    /**
     * 修改订单 card order内容
     */
    public void updateCardOrder() {
        String cardId = getPara("id");
        Record record = shopServices.getCardOrderByCardId(cardId);
        setAttr("record", record);
        setAttr("cardId", cardId);
        renderJsp("editCardOrder.jsp");
    }

    /**
     * 保存orderCard
     */
    public void saveCardOrder() {
        Map<String, String[]> dataMap = getParaMap();
        ReturnData rd = shopServices.saveCardOrder(dataMap);
        renderJson(rd);
    }

    /**
     * 查询建议
     */
    public void adviceList() {
        Map paraMap = getParaMap();
        PageUtil pageUtil = shopServices.rmeoVEd(paraMap);
        setAttr("pageUtil", pageUtil);
        setAttr("type",getPara("type")==null?"0":getPara("type"));
        renderJsp("removedAdvice.jsp");

    }

    /**
     * 删除建议
     */
    public void remove() {
        Map paramap = getParaMap();
        ReturnData ReturnData = shopServices.remove(paramap);
        renderJson(ReturnData);
    }

    /**
     * 跟hotCommodity select框添加option
     */
    public void getCommodityListForHot() {
        List<Record> list = shopServices.getCommodityListForHotList();

        renderJson(list);
    }

    /**
     * 是否有卡号 ,flag 0 闲卡,flag 1 收卡
     */
    public void setSkHasCardNumber() {
        boolean hasNumber = getParaToBoolean("hasNumber");
        String id = getPara("id");
        String hasCardNumber = hasNumber ? "0" : "1";
        String flag = getPara("flag");
        switch (flag) {
            case "0":
                flag = "xy_commodity";
                break;
            case "1":
                flag = "sk_commodity";
                break;
            default:
                break;
        }
        ReturnData rd = shopServices.setHasCardNumber(hasCardNumber, id, flag);
        renderJson(rd);
    }

    /**
     * 重新推送id商品所有因未配置的订单
     */
    public void reSubmitCommodity() {
        String commodityId = getPara("commodityId");
        ReturnData rd = shopServices.reSubmit(commodityId);
        renderJson(rd);
    }

    /**
     * 到重新提交页面
     */
    public void toResubmitCard() {
        String cardId = getPara("cardId");

        Record cardOrder = shopServices.reSubmitCard(cardId);
        setAttr("record", cardOrder);
        renderJsp("reSubmitPage.jsp");
    }

    /**
     * 保存重新提交
     */
    public void resubmitCard() {
        Map<String, String[]> dataMap = getParaMap();
        ReturnData rd = shopServices.submitCard(dataMap);
        renderJson(rd);
    }

    /**
     * isApiNumSet是否配置接口顺序
     */
    public void isApiNumSet() {
        String feedbackId = getPara("feedbackId");
        int num = Db.queryInt("select count(id) from commodity_api_number where faceValueId =?", feedbackId);
        ReturnData rd = new ReturnData(false);
        if (num >= 3) {
            rd.setResult(true);
        } else {
            rd.setResult(false);
        }
        renderJson(rd);
    }
    /**
     * 转账记录
     */
    public void aliLog(){

        String cardId=getPara("cardId");

        PageUtil pageUtil=shopServices.aliLogService(cardId);

        setAttr("pageUtil",pageUtil);

        renderJsp("aliLog.jsp");

    }

    /**
     * 去卡种一键复制
     */
    public void oneButonCopy(){

        String id=getPara("id");

        setAttr("id",id);

        setAttr("cType",getPara("cType"));

        renderJsp("oneButonCopy.jsp");

    }
    /**
     * 保存一键复制
     */
    public void oneButonCopySave(){

        Map<String,String[]> map=getParaMap();

        ReturnData returnData=shopServices.oneButonCopySaveService(map);

        renderJson(returnData);

    }



}
